package com.marvels.approve.loan.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.marvels.approve.loan.dto.McamAutoDecisionWithBLOBs;
import com.marvels.approve.loan.dto.RiskTipsDataDto;
import com.marvels.approve.loan.service.LoanRiskTipsService;
import com.marvels.common.dto.MarvelsResultDTO;
import com.marvels.common.exception.MarvelsBusinessException;
import com.marvels.common.exception.MarvelsErrorCode;
import com.marvels.common.utils.MarvelsLogUtil;

/**风险提示
 * @author hejie
 */
@RestController
@RequestMapping("approve/risktips/service")
public class LoanRiskTipsController {
	@Autowired
	private LoanRiskTipsService loanRiskTipsService;
	
	/**魔蝎验证
	 * @param loanId
	 * @return
	 */
	@RequestMapping("mxData")
	@ResponseBody
	public MarvelsResultDTO queryMxData(@RequestParam("loanId")String loanId) {
		try {
			RiskTipsDataDto mxData = loanRiskTipsService.queryMxData(loanId);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),mxData);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>风险提示 魔蝎验证FAIL:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), e.getMessage(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>风险提示 魔蝎验证异常:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),"风险提示异常");
		}
	}
	
	/**上海资信
	 * @param loanId
	 * @return
	 */
	@RequestMapping("shzxData")
	@ResponseBody
	public MarvelsResultDTO queryShzxData(@RequestParam("loanId")String loanId) {
		try {
			RiskTipsDataDto mxData = loanRiskTipsService.queryShzxData(loanId);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),mxData);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>风险提示 上海资信FAIL:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), e.getMessage(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>风险提示 上海资信异常:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),"风险提示异常");
		}
	}
	
	/**跟历史工单交叉验证
	 * @param loanId
	 * @return
	 */
	@RequestMapping("hisData")
	@ResponseBody
	public MarvelsResultDTO queryHisData(@RequestParam("loanId")String loanId) {
		try {
			RiskTipsDataDto hisData = loanRiskTipsService.queryHisData(loanId);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),hisData);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>风险提示 跟历史工单交叉验证FAIL:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), e.getMessage(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>风险提示 跟历史工单交叉验证异常:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),"风险提示异常");
		}
	}
	
	/**阿里验证
	 * @param loanId
	 * @return
	 */
	@RequestMapping("aliData")
	@ResponseBody
	public MarvelsResultDTO queryAliData(@RequestParam("loanId") String loanId) {
		try {
			RiskTipsDataDto hisData = loanRiskTipsService.queryAlipayData(loanId);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),hisData);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>风险提示 阿里验证FAIL:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), e.getMessage(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>风险提示 阿里验证异常:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),"风险提示异常");
		}
	}
	
	
	/**卡牛房贷还款记录
	 * @param loanId
	 * @return
	 */
	@RequestMapping("knfdData")
	@ResponseBody
	public MarvelsResultDTO queryKNFDData(@RequestParam("loanId") String loanId) {
		try {
			RiskTipsDataDto hisData = loanRiskTipsService.queryKNFDData(loanId);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),hisData);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>风险提示 卡牛房贷还款记录FAIL:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), e.getMessage(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>风险提示 卡牛房贷还款记录:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),"风险提示异常");
		}
	}
	 
	/**51公积金数据
	 * @param loanId
	 * @return
	 */
	@RequestMapping("gjj51Data")
	@ResponseBody
	public MarvelsResultDTO queryGjj51Data(@RequestParam("loanId") String loanId) {
		try {
			RiskTipsDataDto hisData = loanRiskTipsService.queryGjj51Data(loanId);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),hisData);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>风险提示 51公积金数据FAIL:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), e.getMessage(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>风险提示 51公积金数据:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),"风险提示异常");
		}
	}
	
	/**卡牛洗刷刷魔蝎
	 * @param loanId
	 * @return
	 */
	@RequestMapping("knxssData")
	@ResponseBody
	public MarvelsResultDTO queryKnxssData(@RequestParam("loanId") String loanId) {
		try {
			RiskTipsDataDto hisData = loanRiskTipsService.queryKnxssData(loanId);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),hisData);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>风险提示 卡牛洗刷刷魔蝎FAIL:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), e.getMessage(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>风险提示 卡牛洗刷刷魔蝎:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),"风险提示异常");
		}
	}
	
	/**卡牛信用卡
	 * @param loanId
	 * @return
	 */
	@RequestMapping("knData")
	@ResponseBody
	public MarvelsResultDTO queryKnData(@RequestParam("loanId") String loanId) {
		try {
			RiskTipsDataDto hisData = loanRiskTipsService.queryKnData(loanId);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),hisData);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>风险提示 卡牛洗刷刷魔蝎FAIL:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), e.getMessage(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>风险提示 卡牛洗刷刷魔蝎:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),"风险提示异常");
		}
	}
	
	/**
	 * 
	* @Title: queryDecisionData 
	* @Description:查询自动审核数据  
	* @param loanId
	* @return       
	* @author 李瑶
	* @date 2018年10月13日 下午3:16:43
	 */
	@RequestMapping("decisionData")
	@ResponseBody
	public MarvelsResultDTO queryDecisionData(@RequestParam("loanId") String loanId) {
		
		try {
			McamAutoDecisionWithBLOBs decisionData = loanRiskTipsService.queryAutoDecisionData(loanId, null);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),decisionData);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>风险提示 获取自动审核数据FAIL:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), e.getMessage(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>风险提示 获取自动审核数据:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),"风险提示异常");
		}
	}
	
	
	/**
	 * 
	* @Title: queryAntiFraud 
	* @Description: 拉取反欺诈数据 
	* @param loanId
	* @return       
	* @author 李瑶
	* @date 2018年10月22日 上午11:28:06
	 */
	@RequestMapping("antiFraud")
	@ResponseBody
	public MarvelsResultDTO queryAntiFraud(@RequestParam("loanId") String loanId) {
		
		try {
			List list = loanRiskTipsService.queryAntiFraud(loanId);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),list);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>风险提示 获取反欺诈FAIL:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), e.getMessage(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>风险提示 获取反欺诈数据:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),"反欺诈异常");
		}
	}
	
	
}
